using Microsoft.EntityFrameworkCore;
using SheLife.Domain.Entities;
using SheLife.Domain.Interfaces;

namespace SheLife.Infrastructure.Repositories;

public class HabitRepository : Repository<Habit>, IHabitRepository
{
    public HabitRepository(ApplicationDbContext context) : base(context)
    {
    }

    public async Task<IEnumerable<Habit>> GetByUserIdAsync(int userId)
    {
        return await _dbSet
            .Where(h => h.UserId == userId && !h.IsDeleted)
            .OrderByDescending(h => h.CreatedAt)
            .ToListAsync();
    }

    public async Task<IEnumerable<Habit>> GetByUserIdAndCategoryAsync(int userId, string category)
    {
        return await _dbSet
            .Where(h => h.UserId == userId && h.Category == category && !h.IsDeleted)
            .OrderByDescending(h => h.CreatedAt)
            .ToListAsync();
    }

    public async Task<IEnumerable<Habit>> GetActiveHabitsByUserIdAsync(int userId)
    {
        return await _dbSet
            .Where(h => h.UserId == userId && h.IsActive && !h.IsDeleted)
            .OrderByDescending(h => h.CreatedAt)
            .ToListAsync();
    }
}